
interface VaptchaResult { server: string; token: string }


export const getVaptcha = (vid: string) => new Promise<VaptchaResult>((resolve, reject) => {
  const { vaptcha } = window as any;
  vaptcha({
    vid: vid,
    mode: 'invisible',
    scene: 0,
    container: '#VAPTCHAContainer',
    area: 'auto',
  }).then((obj: any) => {
    obj.validate()
    obj.listen('pass', () => {
      const { server, token } = obj.getServerToken();
      resolve({ server, token });
    });
    obj.listen('close', () => reject(new Error("已取消验证")));
  }).catch(reject);
});
